<?php
/* @var $this ContentController */
/* @var $model Content */
/* @var $form CActiveForm */
?>
<div class="clearfix fix-float-left">
    <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
    'id'=>'content-form',
    'enableAjaxValidation'=>true,
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    )
)); ?>
    <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <p><strong>
            <span class="icon16  brocco-icon-mic"></span>
            <?php echo t('Fields with <span class="required">*</span> are required.','fcms'); ?>
        </strong></p>
    </div>

    <?php echo $form->errorSummary($model); ?>

    <div class="row-fluid">
        <div class="tabbable"> <!-- Only required for left/right tabs -->
            <ul class="nav nav-tabs">
                <li class="active"><a href="#tab1" data-toggle="tab"><strong><?php echo t('Content Detail','content'); ?></strong></a></li>
                <li><a href="#tab2" data-toggle="tab"><strong><?php echo t('Media','content'); ?></strong></a></li>
                <li><a href="#tab3" data-toggle="tab"><strong><?php echo t('SEO','content'); ?></strong></a></li>
                <li><a href="#tab4" data-toggle="tab"><strong><?php echo t('Publishing Options','content'); ?></strong></a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="tab1">
                    <div class="span4">
                        <fieldset>
                            <legend><?php echo t('Title','content'); ?></legend>
                            <?php echo $form->textFieldRow($model,'title',array('class'=>'span8','maxlength'=>255,'prepend'=>'<i class="entypo-icon-flash"></i>')); ?>

                            <?php echo $form->textFieldRow($model,'slug',array('class'=>'span8','maxlength'=>255,'prepend'=>'<i class="entypo-icon-flash"></i>')); ?>

                            <?php $this->widget('backend.widgets.Slug.fSlug', array(
                            'model'=>$model,
                            'source' => 'title',
                            'target' => 'slug',
                        )); ?>
                            <?php
                            echo $form->label($model,'image');
                            $this->widget('common.extensions.elfinder.ServerFileInput', array(
                                    'model' => $model,
                                    'attribute' => 'image',
                                    'showImage'=>true,
                                    'noImageAvailable'=>settings()->get('general','no_image_available'),
                                    'htmlOptions'=>array(
                                        'class'=>'nostyle clearfix'
                                    ),
                                    'connectorRoute' => 'elfinder/connector',
                                )
                            );
                            echo $form->error($model,'image');
                            ?>
                        </fieldset>
                    </div>
                    <div class="span4">
                        <fieldset>
                            <legend><?php echo t('Type','content'); ?></legend>
                                <?php
                                echo $form->dropDownListRow($model, 'category_id', Category::getDataCategory(),
                                    array(
                                        'class'=>'span5',
                                    ));
                                ?>

                                <?php
                                echo $form->dropDownListRow($model, 'type',contentType(),
                                    array(
                                        'class'=>'span5',
                                    ));
                                ?>

                                <?php // echo $form->toggleButtonRow($model, 'make_serial',array('class'=>'nostyle'));

                                $data = CHtml::listData(Content::model()->with('category')->findAll(), 'id', 'title','category.name');
                                if(!$data) {
                                    $data = array(
                                        null=>t('No Article','content'),
                                    );
                                }
                                echo $form->label($model,'serial');
                                $this->widget('bootstrap.widgets.TbSelect2', array(
                                    //'asDropDownList' => false,
                                    //'form'=>$form,
                                    'model'=>$model,
                                    'attribute'=>'serial',
                                    'data'=>$data,
                                    'options'=>array(
                                        'placeholder'=>t('Serial','content'),
                                        'allowClear'=>true,
                                        'width'=>'60%'
                                    ),
                                    'htmlOptions'=>array(
                                        'class'=>'nostyle',
                                        'prompt'=>t('No Serial','content')
                                    ),
                                ));
                                echo $form->error($model,'serial');
                                ?>
                                <?php
                                echo $form->dropDownListRow($model, 'multi_categories', Category::getDataCategory(false),
                                    array(
                                        'class'=>'nostyle',
                                        'style'=>'width:auto',
                                        'multiple'=>true
                                    ));
                                ?>
                        </fieldset>
                    </div>
                    <div class="span4">
                        <fieldset>
                            <legend><?php echo t('Detail','content'); ?></legend>
                                <?php echo $form->toggleButtonRow($model, 'is_hot',array('class'=>'nostyle')); ?>
                                <?php echo $form->toggleButtonRow($model, 'sticky',array('class'=>'nostyle')); ?>
                                <?php echo $form->radioButtonGroupsListRow($model, 'allow_comment',array(0=>t('Not Allow','content'),1=>t('Allow','content'),2=>t('Facebook','content'),3=>t('Site','content')),array('class'=>'nostyle')); ?>
                                <?php echo $form->radioButtonGroupsListRow($model, 'status',contentStatus(),array('class'=>'nostyle')); ?>
                        </fieldset>
                    </div>
                    <div class="clearfix">
                        <div class="span12">
                            <?php
                           $editor = settings()->get('general','site_default_editor');
                           switch($editor) {
                               case 'Tinymce':
                               echo $form->label($model,'description');
                               $this->widget('common.extensions.tinymce.TinyMce', array(
                                   'model' => $model,
                                   'attribute' => 'description',
                                   // Optional config
                                   'compressorRoute' => 'tinyMce/compressor',
                                   'spellcheckerRoute' => 'tinyMce/spellchecker',
                                   'settings'=>array(
                                       'theme_advanced_buttons1' => "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                                       'theme_advanced_buttons2' => "cut,copy,paste,|,search,|,undo,redo,|,link,unlink,image,cleanup,|,preview,|,forecolor,backcolor",
                                       'theme_advanced_buttons3' => "tablecontrols,|,emotions,media,|,spellchecker",
                                       'theme_advanced_buttons4' => "styleprops,|,visualchars,nonbreaking,template,pagebreak",
                                   ),
                                   'fileManager' => array(
                                       'class' => 'common.extensions.elfinder.TinyMceElFinder',
                                       'connectorRoute'=>'ElFinder/connector',
                                   ),
                                   'htmlOptions' => array(
                                       'class'=>'nostyle',
                                       'style'=>'height:100px;width:500px'
                                   ),
                               ));
                                   echo $form->error($model,'description');
                                   break;
                               case 'Redactor':
                                   echo $form->redactorRow($model, 'description', array('class'=>'nostyle', 'rows'=>5));
                                   break;
                               case 'Html5':
                                    echo $form->html5EditorRow($model, 'description', array('class'=>'nostyle', 'rows'=>5, 'height'=>'200', 'options'=>array('color'=>true)));
                                    break;
                               case 'CKEditor':
                                   echo $form->ckEditorRow($model, 'description', array('options'=>array('fullpage'=>'js:true', 'width'=>'640', 'resize_maxWidth'=>'640','resize_minWidth'=>'320')));
                                   break;
                               case 'Markdown':
                                   echo $form->markdownEditorRow($model, 'description', array('height'=>'200px'));
                                   break;
                           }
                            ?>
                        </div>
                        <div style="margin-top: 25px;" class="span12 marginL0">
                            <?php
                            $editor = settings()->get('general','site_default_editor');
                            switch($editor) {
                                case 'Tinymce':
                                    echo $form->label($model,'content');
                                    $this->widget('common.extensions.tinymce.TinyMce', array(
                                        'model' => $model,
                                        'attribute' => 'content',
                                        // Optional config
                                        'compressorRoute' => 'tinyMce/compressor',
                                        'spellcheckerRoute' => 'tinyMce/spellchecker',
                                        'fileManager' => array(
                                            'class' => 'common.extensions.elfinder.TinyMceElFinder',
                                            'connectorRoute'=>'ElFinder/connector',
                                        ),
                                        'htmlOptions' => array(
                                            'class'=>'nostyle',
                                            'style'=>'height:100px;width:500px'
                                        ),
                                    ));
                                    echo $form->error($model,'content');
                                    break;
                                case 'Redactor':
                                    echo $form->redactorRow($model, 'content', array('class'=>'nostyle', 'rows'=>5));
                                    break;
                                case 'Html5':
                                    echo $form->html5EditorRow($model, 'content', array('class'=>'nostyle', 'rows'=>5, 'height'=>'200', 'options'=>array('color'=>true)));
                                    break;
                                case 'CKEditor':
                                    echo $form->ckEditorRow($model, 'content', array('options'=>array('fullpage'=>'js:true', 'width'=>'640', 'resize_maxWidth'=>'640','resize_minWidth'=>'320')));
                                    break;
                                case 'Markdown':
                                    echo $form->markdownEditorRow($model, 'content', array('height'=>'200px'));
                                    break;
                            }
                            ?>
                        </div>
                    </div>
                </div>
                <div class="tab-pane" id="tab2">
                    <div class="span6">
                    <fieldset>
                        <legend><?php echo t('Add Images','content'); ?></legend>
                    <?php
                    /*$this->widget('common.extensions.bootstrap.widgets.TbFileUpload',array(
                        'url' => $this->createUrl("content/upload"),
                        'model' => $media,
                        'attribute' => 'url', // see the attribute?
                        'multiple' => true,
                        'options' => array(
                            'maxFileSize' => 2000000,
                            'acceptFileTypes' => 'js:/(\.|\/)(gif|jpe?g|png)$/i',
                    ))); */
                    ?>
                        <?php
                        $imageFormConfig = array(
                            'elements'=>array(
                                'name'=>array(
                                    'type'=>'text',
                                    'maxlength'=>40,
                                ),
                                'url'=>array(
                                    'type'=>'common.extensions.elfinder.ServerFileInput',
                                    'model' => $media,
                                    'attribute' => 'url',
                                    'showImage'=>true,
                                    'noImageAvailable'=>settings()->get('general','no_image_available'),
                                    'htmlOptions'=>array(
                                        'class'=>'nostyle clearfix'
                                    ),
                                    'connectorRoute' => 'elfinder/connector',
                                ),
                                'description'=>array(
                                    'type'=>'textarea',
                                ),
                                'type'=>array(
                                    'type'=>'hidden',
                                    'value'=>'image',
                                ),
                            ));
                        $this->widget('common.extensions.multimodelform.MultiModelForm',array(
                            'id' => 'media_image', //the unique widget id
                            'formConfig' => $imageFormConfig, //the form configuration array
                            'model' => $media, //instance of the form model
                            'bootstrapLayout'=>true,
                            'addItemText'=>t('Add Image','content'),
                            'addItemAsButton'=>true,
                            //if submitted not empty from the controller,
                            //the form will be rendered with validation errors
                            'validatedItems' => $validatedMembers,

                            //array of member instances loaded from db
                            'data' => $media->findAll('content_id=:content_id && type = \'image\'', array(':content_id'=>$model->id)),
                        ));
                        ?>
                    </fieldset>
                    </div>
                    <div class="span6">
                    <fieldset>
                        <legend><?php echo t('Add Video','content'); ?></legend>
                    <?php
                        $videoFormConfig = array(
                            'elements'=>array(
                                'name'=>array(
                                    'type'=>'text',
                                    'maxlength'=>40,
                                    'id'=>'ContentMedia_name_YBUpload'
                                ),
                                'url'=>array(
                                    'type'=>'backend.widgets.uploadYB.uploadYB',
                                    'model'=>$model,
                                    'attribute'=>'url',
                                    'url'=>url('/resource/uploadYB'),
                                    'width'=>700,
                                    'height'=>400,
                                    'idButton'=>'YbUploadBT',
                                ),
                                'description'=>array(
                                    'type'=>'textarea',
                                    'id'=>'ContentMedia_description_YBUpload'
                                ),
                                'type'=>array(
                                    'type'=>'hidden',
                                    'value'=>'video',
                                ),
                            ));
                    $this->widget('common.extensions.multimodelform.MultiModelForm',array(
                        'id' => 'media_video', //the unique widget id
                        'formConfig' => $videoFormConfig, //the form configuration array
                        'model' => $media, //instance of the form model
                        'bootstrapLayout'=>true,
                        'addItemText'=>t('Add video','content'),
                        'addItemAsButton'=>true,
                        //if submitted not empty from the controller,
                        //the form will be rendered with validation errors
                        'validatedItems' => $validatedMembers,

                        //array of member instances loaded from db
                        'data' => $media->findAll('content_id=:content_id && type = \'video\'', array(':content_id'=>$model->id)),
                    ));
                    ?>
                    </fieldset>
                    </div>
                </div>
                <div class="tab-pane" id="tab3">

                    <?php echo $form->textFieldRow($model,'sub_title',array('class'=>'span5','maxlength'=>255)); ?>
                    <?php
                    echo $form->label($model,'meta_keyword');
                    $this->widget('bootstrap.widgets.TbSelect2', array(
                        'asDropDownList' => false,
                        'form'=>$form,
                        'model'=>$model,
                        'attribute'=>'meta_keyword',
                        'options'=>array(
                            'tags'=>array('FCMS'),
                            'placeholder'=>'Keyword',
                            'allowClear'=>true,
                            'width'=>'40%'
                        ),
                    ));
                    echo $form->error($model,'meta_keyword');
                    ?>

                    <?php
                    echo $form->label($model,'meta_robots');
                    $this->widget('bootstrap.widgets.TbSelect2', array(
                        'asDropDownList' => false,
                        'form'=>$form,
                        'model'=>$model,
                        'attribute'=>'meta_robots',
                        'options'=>array(
                            'tags'=>metaRobots(),
                            'placeholder'=>'Robots',
                            'allowClear'=>true,
                            'width'=>'40%',
                            'maximumSelectionSize'=>1
                        ),
                    ));
                    echo $form->error($model,'meta_robots');
                    ?>
                    <?php
                    echo $form->label($model,'meta_revisit_after');
                    $this->widget('bootstrap.widgets.TbSelect2', array(
                        'asDropDownList' => false,
                        'form'=>$form,
                        'model'=>$model,
                        'attribute'=>'meta_revisit_after',
                        'options'=>array(
                            'tags'=>metaRevisitAfter(),
                            'placeholder'=>'Revisit Afer',
                            'allowClear'=>true,
                            'width'=>'40%',
                            'maximumSelectionSize'=>1
                        ),
                    ));
                    echo $form->error($model,'meta_revisit_after');
                    ?>
                    <?php echo $form->textAreaRow($model,'meta_description',array('class'=>'span5')); ?>
                </div>

                <div class="tab-pane" id="tab4">
                        <?php echo $form->textFieldRow($model,'author',array(
                                'class'=>'span5',
                                'prepend'=>'<i class="icon-user"></i>'
                            )
                        ); ?>
                    <div class="row-fluid">
                    <div class="span6">
                        <fieldset>
                            <?php echo $form->datepickerRow($model,'publishing_start',array(
                                    'options'=>array(
                                        'format'=> locale()->getDateFormat('short_calendar'),
                                    ),
                                    'prepend'=>'<i class="icon-calendar"></i>'
                                )
                            );
                            ?>
                            <?php echo $form->timepickerRow($model, 'publishing_start_time', array(
                                'options'=>array(
                                    'minuteStep'=> 5,
                                    'showMeridian'=>timeFormat24()?false:true,
                                    'defaultTime'=>isset($model->publishing_start_time)?'value':'current',
                                ),
                                'append'=>'<i class="icon-time" style="cursor:pointer"></i>')
                            );?>

                        </fieldset>
                    </div>
                    <div class="span6">
                        <fieldset>
                            <?php echo $form->datepickerRow($model,'publishing_end',array(
                                    'options'=>array(
                                        'format'=> locale()->getDateFormat('short_calendar'),
                                    ),
                                    'class'=>'span5',
                                    'prepend'=>'<i class="icon-calendar"></i>'
                                )
                            ); ?>
                            <?php echo $form->timepickerRow($model, 'publishing_end_time', array(
                                    'options'=>array(
                                        'minuteStep'=> 5,
                                        'showMeridian'=>timeFormat24()?false:true,
                                        'defaultTime'=>isset($model->publishing_start_time)?'value':'current',
                                    ),
                                    'append'=>'<i class="icon-time" style="cursor:pointer"></i>')
                            );?>
                        </fieldset>
                    </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="form-actions">
        <?php $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType'=>'submit',
        'type'=>'primary',
         'htmlOptions'=>array(
             'name'=>'Content[submit]',
             'value'=>'default'
         ),
        'label'=>$model->isNewRecord ? t('Create','fcms') : t('Save','fcms'),
    ));
        $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType'=>'submit',
         'htmlOptions'=>array(
             'name'=>'Content[submit]',
             'value'=>'close'
         ),
        'label'=>$model->isNewRecord ? t('Create & Close') : t('Save & Close'),
    ));
        $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType'=>'submit',
         'htmlOptions'=>array(
             'name'=>'Content[submit]',
             'value'=>'new'
         ),
        'label'=>$model->isNewRecord ? t('Create & New') : t('Save & New'),
    ));
        $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType'=>'reset',
            'label'=>t('Reset'),
        ));
        ?>
    </div>

    <?php $this->endWidget(); ?>
</div>